<?php


namespace app\api\controller\v13;


use app\api\controller\v2\Auth;
use think\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;
use think\response\Json;

class Recode extends Auth
{
    /**
     * 查询用户档案列表
     * @param null $id
     * @return Json [type] [description]
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     */
    public function index($id = NULL)
    {
        if ($id === NULL)
        {
            $id = input('id/d', 0);
        }
        $uid = $this->user['id'];
        if ($id)
        {
            $data = Db::table('app_recode')->alias('r')
                ->join('app_recode_astro ra', 'r.id=ra.rid', 'INNER')
                ->field('r.id,r.name,r.type,r.year,r.month,r.day,r.hour,r.minute,r.timezone,birth_country,birth_province,birth_city,live_country,live_province,live_city,comments,isself,long_deg,long_min,ew,lat_deg,lat_min,ns,avatar,is_summer,uid,aid,sun,moon,merc,venu,mars,jupi,satu,non,lili,juno,asc,mc,r.is_read')
                ->where(['r.id' => $id, 'uid' => $uid])
                ->find();
            if (empty($data))
            {
                return json(['code' => 10322, 'msg' => '档案不存在']);
            }
        } else
        {
            $data = Db::table('app_recode')->alias('r')
                ->join('app_recode_astro ra', 'r.id=ra.rid', 'INNER')
                ->field('r.id,r.name,r.type,r.year,r.month,r.day,r.hour,r.minute,r.timezone,birth_country,birth_province,birth_city,live_country,live_province,live_city,comments,isself,long_deg,long_min,ew,lat_deg,lat_min,ns,avatar,is_summer,uid,aid,sun,moon,merc,venu,mars,jupi,satu,non,lili,juno,asc,mc,r.is_read')
                ->where(['uid' => $uid, 'status' => 1])
                ->select();
        }
        return json(['code' => 200, 'data' => $data, 'msg' => 'ok']);
    }
}
